//
//  ViewController.swift
//  SnowVision
//
//  Created by 谦也 on 2025/3/4.
//

import UIKit
import AMapSearchKit

class ViewController: UIViewController {

    private lazy var search = {
        AMapSearchAPI.updatePrivacyShow(.didShow, privacyInfo: .didContain)
        AMapSearchAPI.updatePrivacyAgree(.didAgree)
        let search = AMapSearchAPI()
        search?.delegate = self
        return search
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.reGoecodeSearch(coor: CLLocationCoordinate2D(latitude: 0.00012, longitude: 0.00003))
    }


    func transCoordFromGPS(coor:CLLocationCoordinate2D) -> CLLocationCoordinate2D {
        return AMapCoordinateConvert(coor, AMapCoordinateType.GPS)
    }
}

extension ViewController : AMapSearchDelegate {
    func reGoecodeSearch(coor:CLLocationCoordinate2D) {
        let tranCoor = self.transCoordFromGPS(coor: coor)
        let regeo = AMapReGeocodeSearchRequest()
        regeo.location = AMapGeoPoint.location(withLatitude: tranCoor.latitude, longitude: tranCoor.longitude)
        regeo.requireExtension = true
        self.search?.aMapReGoecodeSearch(regeo)
    }
    
    func onReGeocodeSearchDone(_ request: AMapReGeocodeSearchRequest!, response: AMapReGeocodeSearchResponse!) {
        
    }
    
    func aMapSearchRequest(_ request: Any!, didFailWithError error: (any Error)!) {

    }
}

